package logic

import (
	"context"
	"errors"
	"video-joy/models/mysql"

	"video-joy/userrpc/internal/svc"
	"video-joy/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 视频添加
func (l *VideoAddLogic) VideoAdd(in *userrpc.VideoAddRequest) (*userrpc.VideoAddResponse, error) {
	// todo: add your logic here and delete this line

	video := &mysql.VideoInfo{
		UserId:        in.UserId,
		VideoTitle:    in.VideoTitle,
		VideoCategory: in.VideoCategory,
		VideoLink:     in.VideoLink,
		CoverLink:     in.CoverLink,
		VideoIntro:    in.VideoIntro,
		PlayNum:       int(in.PlayNum),
		LikeNum:       int(in.LikeNum),
		CollectNum:    int(in.CollectNum),
		VideoStatus:   int(in.VideoStatus),
		TopicId:       int(in.TopicId),
	}

	if err := video.VideoAdd(mysql.DB); err != nil {
		return nil, errors.New("视频添加失败")
	}

	return &userrpc.VideoAddResponse{
		VideoId: int64(video.ID),
	}, nil
}
